package com.lexed.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.lexed.pojo.Emp;
import com.lexed.service.EmpService;

/**
 * Servlet implementation class Login
 */
public class Login extends HttpServlet {
	
	private EmpService empService = new EmpService();
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		try {
			Emp emp = empService.selectByUname(username);
			if(emp != null && emp.getPwd().equals(password)){
				
				// 保存用户信息到session中
				HttpSession session = request.getSession();
				session.setAttribute("user", emp);
				
				response.sendRedirect("manager.html");
			}else{
				response.sendRedirect("login.html");
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.sendRedirect("login.html");
		}
		
	}



}
